﻿using static System.Console;

MyDelegate my1 = new MyDelegate(PrintMsg);
my1("hello delegate");

MyDelegate my2 = PrintMsg;
my2("hello world");

static void PrintMsg(string message)
{
    WriteLine(message);
}

// 使用Lambda表达式
MyDelegate my3 = (string msg) => Console.WriteLine(msg);
my3("hello lambda");

AddDel addDel = (int a, int b) => { return a + b; };
int sum = addDel(4, 4);
WriteLine(sum);

ReadLine();

// 声明一个委托
public delegate void MyDelegate(string message);

public delegate int AddDel(int a, int b);